/* GUI CONVERTED from ecbmpsiq.p (converter v1.76) Tue Dec 31 10:45:01 2002 */
/* ecbmpsiq.p - PRODUCT STRUCTURE INQUIRY                                      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                         */
/* All rights reserved worldwide.  This is an unpublished work.                */
/* $Revision: 1.8.1.6 $                                                        */
/*V8:ConvertMode=Report                                                        */
/* REVISION: 1.0             LAST EDIT: 06/11/86       MODIFIED BY: EMB        */
/* REVISION: 1.0             LAST EDIT: 11/03/86       MODIFIED BY: EMB *12*   */
/* REVISION: 1.0             LAST EDIT: 11/03/86       MODIFIED BY: EMB *36*   */
/* REVISION: 2.0             LAST EDIT: 03/23/87       MODIFIED BY: EMB *12*   */
/* REVISION: 2.1             LAST EDIT: 10/20/87       MODIFIED BY: WUG *A94*  */
/* REVISION: 4.0             LAST EDIT: 12/30/87                BY: WUG*A137*  */
/* REVISION: 4.0             LAST EDIT: 04/28/88       MODIFIED BY: EMB(*12*)  */
/* REVISION: 5.0             LAST EDIT: 05/03/89                BY: WUG *B098* */
/* REVISION: 7.0             LAST EDIT: 03/23/92       MODIFIED BY: emb *F671* */
/* Revision: 7.3             Last edit: 11/19/92             By: jcd *G345*    */
/* REVISION: 7.3             LAST EDIT: 02/24/93             BY: sas *G740*    */
/* REVISION: 7.4             LAST EDIT: 12/01/93             BY: qzl *H013*    */
/* REVISION: 7.4         LAST MODIFIED: 08/16/93             BY: qzl *H343*    */
/* REVISION: 7.4         LAST MODIFIED: 12/01/94             BY: qzl *H612*    */
/* REVISION: 8.5         LAST MODIFIED: 07/31/96   BY: *J12T* Sue Poland       */
/* REVISION: 8.6         LAST MODIFIED: 12/06/96   BY: *K00C* Joe Gawel        */
/* REVISION: 8.6         LAST MODIFIED: 10/07/97   BY: *K0LP* John Worden      */
/* REVISION: 8.6         LAST MODIFIED: 10/20/97   BY: mur *K132*              */
/* REVISION: 8.6E        LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane        */
/* REVISION: 8.6E        LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan       */
/* REVISION: 9.1         LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1         LAST MODIFIED: 08/14/00   BY: *N0KW* Jacolyn Neder    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.8.1.6 $    BY: Katie Hilbert    DATE: 12/27/02  ECO: *P0L8*   */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* Modified bmpsiq.p for PCC module          */

/* DISPLAY TITLE */

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}
define shared variable global_recid as recid.

define variable comp      like ps_comp.
define variable level     as integer.
define variable maxlevel  as integer format ">>>" label "Levels".
define variable eff_date  like ar_effdate.
define variable parent    like ps_par.
define variable desc1     like pt_desc1.
define variable um        like pt_um.
define variable phantom   like mfc_logical format "yes" label "Ph".
define variable iss_pol   like pt_iss_pol format "/no".
define variable record    as integer extent 100.
define variable lvl       as character format "x(7)" label "Level".
define variable ecmnbr    like ecm_nbr.
define variable ecmid     like wo_lot.
define variable dbase     like si_db.
define buffer psmstr for ps_mstr.

eff_date = today.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
parent       colon 14
   desc1        colon 38 no-label
   um           colon 65 no-label
   ecmnbr       colon 14
   ecmid        colon 32
   dbase        colon 52
   ecm_doc_type colon 70 format "x(3)" no-label
   eff_date     colon 14
   maxlevel     colon 32
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   lvl
   ps_mstr.ps_comp
   desc1              format "x(17)"
   um
   ps_mstr.ps_qty_per column-label "Qty Per"
   ps_mstr.ps_ps_code column-label "T"
   ecd1_qty_per_b     column-label "PCC Qty Per"
   ecd1__qad03        format "x(1)" column-label "T"
with STREAM-IO /*GUI*/  frame heading width 80
   no-attr-space down.

/* SET EXTERNAL LABELS */
setFrameLabels(frame heading:handle).

/* SET PARENT TO GLOBAL PART NUMBER */
parent = global_part.

{wbrp01.i}
block-rpt:
repeat on error undo, retry:

   if c-application-mode <> 'web' then
   update
      parent
      ecmnbr
      ecmid
      dbase
      eff_date
      maxlevel
   with frame a
   editing:

      if frame-field = "parent" then do:
         /* NEXT/PREV THRU 'NON-SERVICE' BOMS */
         {mfnp05.i bom_mstr bom_fsm_type "bom_fsm_type = """" "
            bom_parent "input parent"}

         if recno <> ? then do:
            parent = bom_parent.
            display bom_parent @ parent with frame a.
            find pt_mstr where pt_part = parent no-lock no-error.
            if available pt_mstr then
               display
                  pt_desc1 @ desc1
                  pt_um    @ um
               with frame a.
            else
               display
                  bom_desc     @ desc1
                  bom_batch_um @ um
               with frame a.
            recno = ?.
         end.
      end.    /* if frame-field = "parent" */
      else if frame-field = "ecmnbr" then do:
         global_recid = ?.
         {mfnp05.i ecm_mstr ecm_mstr
            "(ecm_eff_date = ? and ecm_close_date = ?)"
            ecm_nbr "input ecmnbr"}
         if global_recid <> ? then do:
            recno = global_recid.
            find ecm_mstr where recid(ecm_mstr) = recno.
            global_recid = ?.
         end.

         if recno <> ? then
            display
               substring(ecm_nbr,1,8)  @ ecmnbr
               substring(ecm_nbr,9,8)  @ ecmid
               substring(ecm_nbr,17,8) @ dbase
               ecm_doc_type
            with frame a.
      end.    /* else if frame-field = "ecmnbr" */
      else do:
         status input.
         readkey.
         apply lastkey.
      end.
   end.

   {wbrp06.i &command = update &fields = "  parent ecmnbr ecmid dbase
        eff_date maxlevel" &frm = "a"}

   if (c-application-mode <> 'web') or
      (c-application-mode = 'web' and
      (c-web-request begins 'data'))
   then do:

      find ecm_mstr where ecm_nbr = string(ecmnbr,"x(8)") +
                                    string(ecmid,"x(8)")  +
                                    string(dbase,"x(8)")
      no-lock no-error.
      if not available ecm_mstr then do:
         {pxmsg.i &MSGNUM=2155 &ERRORLEVEL=3}    /* PCO does not exist */

         if c-application-mode = 'web' then return.
         else next-prompt ecmnbr with frame a.
         undo, retry.
      end.
      else
      if available ecm_mstr and (ecm_eff_date <> ? or ecm_close_date <> ?)
      then do:
         /* PCO has been incorporated or closed */
         {pxmsg.i &MSGNUM=2153 &ERRORLEVEL=3}

         if c-application-mode = 'web' then return.
         else next-prompt ecmnbr with frame a.
         undo, retry.
      end.

      assign
         desc1 = ""
         um    = "".

      find pt_mstr use-index pt_part where pt_part = parent no-lock no-error.
      if available pt_mstr then do:
         assign
            um     = pt_um
            desc1  = pt_desc1
            parent = pt_part.
      end.
      else do:
         find bom_mstr no-lock where bom_parent = parent no-error.
         if available bom_mstr
         then do:

            /* WARN USER IF A SERVICE BOM */
            if bom_fsm_type = "FSM" then do:
               /* THIS IS AN SSM BILL OF MATERIAL */
               /* not a standard bill of material */
               {pxmsg.i &MSGNUM=7487 &ERRORLEVEL=2}
            end.     /* if bom_fsm_type = "FSM" */
            assign
               um     = bom_batch_um
               parent = bom_parent.
         end.
      end.    /* else, not available pt_mstr, do */

      if not available pt_mstr and not available bom_mstr
      then do:
         hide message no-pause.
         /* PART NUMBER DOES NOT EXIST. */
         {pxmsg.i &MSGNUM=17 &ERRORLEVEL=3}
         display
            desc1
            um
         with frame a.
         if c-application-mode = 'web' then return.
         undo, retry.
      end.    /* if not available pt_mstr and ... */

      display parent desc1 um with frame a.

      clear frame heading all no-pause.
      hide frame heading.

   end.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "terminal"
               &printWidth = 80
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "no"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   assign
      level = 1
      comp = parent
      maxlevel = min(maxlevel,99).

   find first ps_mstr use-index ps_parcomp where ps_mstr.ps_par = comp
   no-lock no-error.
   repeat with frame heading:

      
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


      if not available ps_mstr then do:
         repeat:
            level = level - 1.
            if level < 1 then leave.
            find ps_mstr
               where recid(ps_mstr) = record[level]
            no-lock no-error.
            comp = ps_mstr.ps_par.
            find next ps_mstr use-index ps_parcomp
               where ps_mstr.ps_par = comp
            no-lock no-error.
            if available ps_mstr then leave.
         end.
      end.
      if level < 1 then leave.

      if eff_date = ? or (eff_date <> ? and
         (ps_mstr.ps_start = ? or ps_mstr.ps_start <= eff_date)
         and (ps_mstr.ps_end = ? or eff_date <= ps_mstr.ps_end))
      then do with frame heading:

         assign
            um      = ""
            desc1   = ""
            iss_pol = no
            phantom = no
            record[level] = recid(ps_mstr)
            lvl = "......."
            lvl = substring(lvl,1,min(level - 1,6)) + string(level).

         if length(lvl) > 7 then lvl = substring(lvl,length(lvl) - 6,7).

         find first psmstr
            where psmstr.ps_par = ps_mstr.ps_par and
                 (psmstr.ps_start <= eff_date or ps_start = ?) and
                 (psmstr.ps_end >= eff_date or ps_end = ?) no-error.
         if available psmstr and ps_mstr.ps_par   = psmstr.ps_par  and
                                 ps_mstr.ps_comp  = psmstr.ps_comp and
                                 ps_mstr.ps_ref   = psmstr.ps_ref  and
                                 ps_mstr.ps_start = psmstr.ps_start
         then do:
            for each ecd1_det
               where ecd1_nbr = string(ecmnbr,"x(8)")
                              + string(ecmid,"x(8)")
                              + string(dbase,"x(8)")
                 and ecd1_par = ps_par no-lock:
               find first psmstr
                  where psmstr.ps_par = ecd1_par
                    and psmstr.ps_comp = ecd1_comp
                    and psmstr.ps_ref = ecd1_ref
                    and (psmstr.ps_start = ? or psmstr.ps_start <= eff_date)
                    and (psmstr.ps_end = ? or psmstr.ps_end >= eff_date)
               no-error.
               if available psmstr then next.

               find pt_mstr where pt_part = ecd1_comp no-lock no-error.
               if available pt_mstr then
                  assign
                     um      = pt_um
                     desc1   = pt_desc1
                     iss_pol = pt_iss_pol
                     phantom = pt_phantom.
               else do:
                  find bom_mstr no-lock where bom_parent = ecd1_comp no-error.
                  if available bom_mstr then
                     assign
                        um    = bom_batch_um
                        desc1 = bom_desc.
               end.

               display
                  lvl ecd1_comp @ ps_mstr.ps_comp
                  desc1
                  um
                  0 @ ps_mstr.ps_qty_per
                  ecd1_qty_per_b
                  "" @
                  ps_mstr.ps_ps_code
                  ecd1__qad03
               with frame heading STREAM-IO /*GUI*/ .
               down with frame heading.

               if available pt_mstr and pt_desc2 > ""
               then do with frame heading:
                  display pt_desc2 @ desc1 WITH STREAM-IO /*GUI*/ .
                  down 1.
               end.
            end.     /* for each ecd1_det */
         end.     /* if available psmstr.... */

         find pt_mstr where pt_part = ps_mstr.ps_comp no-lock no-error.
         if available pt_mstr then
            assign
               um      = pt_um
               desc1   = pt_desc1
               iss_pol = pt_iss_pol
               phantom = pt_phantom.
         else do:
            find bom_mstr no-lock where bom_parent = ps_mstr.ps_comp no-error.
            if available bom_mstr then
               assign
                  um    = bom_batch_um
                  desc1 = bom_desc.
         end.

         find ecd1_det
            where ecd1_nbr = string(ecmnbr,"x(8)")
                           + string(ecmid,"x(8)")
                           + string(dbase,"x(8)")
              and ecd1_par = ps_mstr.ps_par
              and ecd1_ref = ps_mstr.ps_ref
         no-lock no-error.

         display
            lvl
            ps_mstr.ps_comp
            desc1
            ps_mstr.ps_qty_per
            um
            ps_mstr.ps_ps_code WITH STREAM-IO /*GUI*/ .

         find bom_mstr where bom_parent = ps_mstr.ps_par no-lock no-error.
         if available bom_mstr and bom_formula then
            display
               ps_mstr.ps_qty_per_b @ ps_mstr.ps_qty_per WITH STREAM-IO /*GUI*/ .
         else
            display
               ps_mstr.ps_qty_per WITH STREAM-IO /*GUI*/ .

         if available ecd1_det then do:
            if ecd1__qad01 then
               display
                  0 @ ecd1_qty_per_b WITH STREAM-IO /*GUI*/ .
            else
               display
                  ecd1_qty_per_b WITH STREAM-IO /*GUI*/ .
            display
               ps_mstr.ps_ps_code
               ecd1__qad03 WITH STREAM-IO /*GUI*/ .
         end.
         down.

         if available pt_mstr and pt_desc2 > ""
         then do with frame heading:
            display pt_desc2 @ desc1 WITH STREAM-IO /*GUI*/ .
            down.
         end.

         if level < maxlevel or maxlevel = 0 then do:
            assign
               comp  = ps_mstr.ps_comp
               level = level + 1.
            find first ps_mstr use-index ps_parcomp
               where ps_mstr.ps_par = comp
            no-lock no-error.
         end.
         else
            find next ps_mstr use-index ps_parcomp
               where ps_mstr.ps_par = comp
            no-lock no-error.
      end.    /* if eff_date = ? ... */
      else
         find next ps_mstr use-index ps_parcomp
            where ps_mstr.ps_par = comp
         no-lock no-error.
   end.    /* repeat with frame heading */

   {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

   {pxmsg.i &MSGNUM=8 &ERRORLEVEL=1}

end.   /* repeat */
global_part = parent.

{wbrp04.i &frame-spec = a}
